package baibeiwallet.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.InputType;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alm.token.MyApp;
import com.alm.token.R;
import com.alm.token.ui.activity.BindEmaiActivity;
import com.alm.token.ui.activity.BindGoogleCodeActivity;
import com.alm.token.ui.activity.MainActivity;
import com.alm.token.ui.activity.PayPwdActivity;
import com.alm.token.ui.data.BaseDialogBean;
import com.alm.token.ui.data.bean.UserWalletData;
import com.alm.token.ui.fragmentDialog.ToBindDialogFragment;
import com.alm.token.ui.fragmentDialog.ToSetPayPswDialogFragment;
import com.alm.token.utils.EmptyUtils;
import com.alm.token.utils.LanguageUtils;
import com.alm.token.utils.MyOnclickListener;
import com.alm.token.utils.PopupAdapter;
import com.alm.token.widget.CommonPopupWindow;
import com.alm.token.widget.Countdownbutton;
import com.alm.token.widget.GoogleCodewordView;
import com.alm.token.widget.PayPasswordView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import baibeiwallet.BaibeiWallet;

import static com.alm.token.ConStant.county;
import static com.alm.token.ConStant.countyID;
import static com.alm.token.ui.activity.BindEmaiActivity.BINDMAI_bind;
import static com.alm.token.ui.activity.BindGoogleCodeActivity.BINDGOOGLECODE_BINd;
import static com.alm.token.ui.fragmentDialog.ToBindDialogFragment.BINDTYPE_GOOGLECODE;
import static com.alm.token.ui.fragmentDialog.ToBindDialogFragment.BINDTYPE_MAIL;
import static com.alm.token.ui.fragmentDialog.ToBindDialogFragment.BINDTYPE_MONIC;


/**
 * TODO 写清楚此类的作用
 *
 * @author Try
 * @date 2018/9/13 14:18
 */
public class DialogUtils {
    private static String[] countys = new String[14];

    public interface IEnterPwdListener {
        void onSuccess(String pwd);
    }

    public interface IEnterPwdListener2 {
        void onSuccess(String pwd, String code, String googleCode);
    }

    public interface IEnterPwdListener3 {
        void onSendSms(String code1);

    }

    public interface IEnterPwdListener4 {
        void oninToFundArea(boolean flag);
    }


    public static void hide(Context context, View view) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }


    public static void enterPwd(Activity activity, IEnterPwdListener successListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_pwd3, null, false);
        AlertDialog alert = builder.setView(view)
                .create();
        EditText etPwd = view.findViewById(R.id.et_pwd);
        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(activity, "取消输入", Toast.LENGTH_SHORT).show();
                hide(activity, etPwd);
                alert.dismiss();

            }
        });
        view.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (successListener != null) {
                    successListener.onSuccess(etPwd.getText().toString());
                }
                hide(activity, etPwd);
//                Toast.makeText(activity, "密码是 " + etPwd.getText().toString(), Toast.LENGTH_SHORT).show();
                alert.dismiss();
            }
        });
        alert.show();
    }

    public static void enterUserinfor(Activity activity, CharSequence title_hint, int inputType, IEnterPwdListener successListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_pwd3, null, false);
        AlertDialog alert = builder.setView(view)
                .create();
        TextView tvTitle = view.findViewById(R.id.tv_title);
        tvTitle.setText(title_hint);
        EditText etPwd = view.findViewById(R.id.et_pwd);
        etPwd.setInputType(inputType);//InputType.TYPE_CLASS_TEXT
        etPwd.setHint(title_hint);
        etPwd.setHintTextColor(activity.getResources().getColor(R.color.colorPrimary666666));
        etPwd.setTextColor(activity.getResources().getColor(R.color.colorPrimary444444));
//        etPwd.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.shape_white));
        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(activity, "取消输入", Toast.LENGTH_SHORT).show();
                hide(activity, etPwd);
                alert.dismiss();

            }
        });
        view.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (successListener != null) {
                    successListener.onSuccess(etPwd.getText().toString());
                }
                hide(activity, etPwd);
//                Toast.makeText(activity, "密码是 " + etPwd.getText().toString(), Toast.LENGTH_SHORT).show();
                alert.dismiss();
            }
        });
        alert.show();
    }

    public static void showInfor(Activity activity, UserWalletData.DataBean.SysMsgBean sysMsgBean, IEnterPwdListener successListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_sysmsg, null, false);
        AlertDialog alert = builder.setView(view)
                .create();

        TextView title = view.findViewById(R.id.tv_title);
        title.setText(sysMsgBean.getTitle());

        TextView conten = view.findViewById(R.id.tv_content);
        conten.setText(sysMsgBean.getContent());
        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(activity, "取消输入", Toast.LENGTH_SHORT).show();
                MyApp.canTanchuang = false;
                alert.dismiss();

            }
        });
        view.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (successListener != null) {
                    successListener.onSuccess("");
                }
//                Toast.makeText(activity, "密码是 " + etPwd.getText().toString(), Toast.LENGTH_SHORT).show();
                alert.dismiss();
            }
        });
        alert.show();
    }


    public static void showUserMsgInfor(Activity activity, UserWalletData.DataBean.UserMsgBean userMsgBean, IEnterPwdListener successListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_sysmsg, null, false);
        AlertDialog alert = builder.setView(view)
                .create();

        TextView title = view.findViewById(R.id.tv_title);
        title.setText(LanguageUtils.getSetIndex() == 1 ? userMsgBean.getTitle() : userMsgBean.getEnTitle());

        TextView conten = view.findViewById(R.id.tv_content);
        conten.setText(LanguageUtils.getSetIndex() == 1 ? userMsgBean.getContent() : userMsgBean.getEnContent());
        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(activity, "取消输入", Toast.LENGTH_SHORT).show();
                alert.dismiss();
            }
        });
        view.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (successListener != null) {
                    successListener.onSuccess("");
                }
//                Toast.makeText(activity, "密码是 " + etPwd.getText().toString(), Toast.LENGTH_SHORT).show();
                alert.dismiss();
            }
        });
        alert.show();
    }

    public static void showInfor1(Activity activity, UserWalletData.DataBean.SysMsgBean sysMsgBean, IEnterPwdListener successListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_sysmsg, null, false);
        AlertDialog alert = builder.setView(view)
                .create();

        TextView title = view.findViewById(R.id.tv_title);
        title.setText(sysMsgBean.getTitle());

        TextView conten = view.findViewById(R.id.tv_content);
        conten.setText(sysMsgBean.getContent());
        TextView click1 = view.findViewById(R.id.btn_cancel);
        click1.setText(activity.getString(R.string.common_cancel));
        TextView click2 = view.findViewById(R.id.btn_confirm);
        click2.setText(activity.getString(R.string.common_ok));

        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(activity, "取消输入", Toast.LENGTH_SHORT).show();
                alert.dismiss();

            }
        });
        view.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (successListener != null) {
                    successListener.onSuccess("");
                }
//                Toast.makeText(activity, "密码是 " + etPwd.getText().toString(), Toast.LENGTH_SHORT).show();
                alert.dismiss();
            }
        });
        alert.show();
    }

    public static void enterPwd1(Activity activity, IEnterPwdListener successListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_pwd3, null, false);
        AlertDialog alert = builder.setView(view)
                .create();
        EditText etPwd = view.findViewById(R.id.et_pwd);
        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(activity, "取消输入", Toast.LENGTH_SHORT).show();
                hide(activity, etPwd);
                alert.dismiss();

            }
        });
        view.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (successListener != null) {
                    successListener.onSuccess(etPwd.getText().toString());
                }
                hide(activity, etPwd);
//                Toast.makeText(activity, "密码是 " + etPwd.getText().toString(), Toast.LENGTH_SHORT).show();
                alert.dismiss();
            }
        });
        alert.show();
    }

    public static void enterPwd2(Activity activity, BaibeiWallet wallet, IEnterPwdListener successListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_setwalletname_pwd3, null, false);
        AlertDialog alert = builder.setView(view)
                .create();
        EditText etPwd = view.findViewById(R.id.et_pwd);
        EditText etName = view.findViewById(R.id.et_name);

        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(activity, "取消输入", Toast.LENGTH_SHORT).show();
                hide(activity, etPwd);
                alert.dismiss();

            }
        });
        view.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (wallet.getPassword().equalsIgnoreCase(etPwd.getText().toString())) {
                    if (successListener != null) {
                        successListener.onSuccess(etName.getText().toString());
                    }
                    hide(activity, etPwd);
//                    Toast.makeText(activity, "密码是 " + etPwd.getText().toString(), Toast.LENGTH_SHORT).show();
                    alert.dismiss();
                } else {
                    Toast.makeText(activity, activity.getString(R.string.wallet_hint_warn12), Toast.LENGTH_SHORT).show();
                }
            }
        });
        alert.show();
    }


    public static void showInforsetLang(Activity activity, UserWalletData.DataBean.SysMsgBean sysMsgBean, IEnterPwdListener successListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_sysmsg, null, false);
        AlertDialog alert = builder.setView(view)
                .create();

        TextView title = view.findViewById(R.id.tv_title);
        title.setText(sysMsgBean.getTitle());
        TextView conten = view.findViewById(R.id.tv_content);
        conten.setText(sysMsgBean.getContent());
        TextView click1 = view.findViewById(R.id.btn_cancel);
        click1.setText(sysMsgBean.getUpStartTimeStr());
        TextView click2 = view.findViewById(R.id.btn_confirm);
        click2.setText(sysMsgBean.getUpEndTimeStr());

        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(activity, "取消输入", Toast.LENGTH_SHORT).show();
                alert.dismiss();

            }
        });
        view.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (successListener != null) {
                    successListener.onSuccess("");
                }
//                Toast.makeText(activity, "密码是 " + etPwd.getText().toString(), Toast.LENGTH_SHORT).show();
                alert.dismiss();
            }
        });
        alert.show();
    }

    static TextView tvSetphonecode;
    static TextView edtInputphone;
    static TextView tvClickphonecountry;

    public static TextView getTvSetphonecode() {
        return tvSetphonecode;
    }

    public static TextView getTvClickphonecountry() {
        return tvClickphonecountry;
    }


    public static ToBindDialogFragment dialogFragment;

    public static void toBind(Activity activity, FragmentManager supportFragmentManager, boolean isPayPwd, boolean bindEmail, boolean bindMnemonic, boolean bindGoogleCode) {
        if (bindEmail && bindMnemonic && !isPayPwd) {
            if (EmptyUtils.isNotEmpty(dialogFragment)) {
                dialogFragment.dismissParent();
            }
            UserWalletData.DataBean.UserMsgBean userMsgBean = new UserWalletData.DataBean.UserMsgBean();
            userMsgBean.setTitle(activity.getString(R.string.common_warmprompt));
            userMsgBean.setContent(activity.getString(R.string.dialog_hint_tosetpaypsw_worm));

            ToSetPayPswDialogFragment dialogFragment = new ToSetPayPswDialogFragment();
            dialogFragment.setDialogBean(new BaseDialogBean("eggroal", userMsgBean));

            dialogFragment.setListener(new ToSetPayPswDialogFragment.ClickListener() {
                @Override
                public void Listener(String name, int potion) {
//                showToast(getString(R.string.paypasw_hint_setpaypsw));
                    Intent intent = new Intent(activity, PayPwdActivity.class);
                    intent.putExtra("PayPwdActivityType", PayPwdActivity.PAYPSW_SET);
                    activity.startActivity(intent);
                }
            });
            dialogFragment.show(supportFragmentManager, "ToSetPayPswDialogFragment");
            supportFragmentManager.executePendingTransactions();
        } else if (!bindEmail || !bindMnemonic || !bindGoogleCode) {

            UserWalletData.DataBean.UserMsgBean userMsgBean = new UserWalletData.DataBean.UserMsgBean();
            userMsgBean.setTitle(activity.getString(R.string.common_warmprompt));
            String content = activity.getString(!bindEmail ? R.string.dialog_hint_tobindmai_worm : !bindMnemonic ? R.string.dialog_hint_tobindmonic_worm :
                    R.string.dialog_hint_tobindgooglecode_worm);
            userMsgBean.setContent(content);

            int type = !bindEmail ? BINDTYPE_MAIL : !bindMnemonic ? BINDTYPE_MONIC : BINDTYPE_GOOGLECODE;

            if (EmptyUtils.isNotEmpty(dialogFragment)) {
                dialogFragment.dismissParent();
            }
            dialogFragment = new ToBindDialogFragment();
            dialogFragment.setDialogBean(new BaseDialogBean(type, userMsgBean));

            dialogFragment.setListener(new ToBindDialogFragment.ClickListener() {
                @Override
                public void Listener(String name, int type) {
                    if (type == BINDTYPE_MAIL || type == BINDTYPE_MONIC) {
                        //强制性绑定邮箱  绑定邮箱需要查看是否设置了支付密码，设置了支付密码需要检测支付密码
                        Intent intent = new Intent(activity, BindEmaiActivity.class);
                        intent.putExtra("BINDMAI_type", BINDMAI_bind);
                        activity.startActivity(intent);
                    } else if (type == BINDTYPE_GOOGLECODE) {
                        //非强制性绑定谷歌验证码
                        Intent intent = new Intent(activity, BindGoogleCodeActivity.class);
                        intent.putExtra("BINDGOOGLECODE_type", BINDGOOGLECODE_BINd);
                        activity.startActivity(intent);
                    }

//                    else if (type ==BINDTYPE_MONIC) {
//                        //强制性绑定助记词
//                        //生成助记词
//                        startActivity(MnemonicActivity.class);
//                    }
//        else if (bindGoogleCode) {
//            //非强制性绑定谷歌验证码
//            Intent intent = new Intent(MainActivity.this, BindGoogleCodeActivity.class);
//            intent.putExtra("BINDGOOGLECODE_type", BINDGOOGLECODE_UNBINd);
//            startActivity(intent);
//        }

//                    else if (bindEmail) {
//                        Intent intent = new Intent(MainActivity.this, BindEmaiActivity.class);
//                        intent.putExtra("BINDMAI_type", BINDMAI_up);
//                        startActivity(intent);
//                    }
                }
            });

            dialogFragment.show(supportFragmentManager, "ToBindDialogFragment");
            supportFragmentManager.executePendingTransactions();
        }

    }


    public static AlertDialog showVerify(Activity activity, IEnterPwdListener2 successListener, IEnterPwdListener3 successListener1, IEnterPwdListener4 successListener2) {
        for (int i = 0; i < countys.length; i++) {
            countys[i] = activity.getResources().getString(county[i]);
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_verify, null, false);
        AlertDialog alert = builder.setView(view)
                .create();

        EditText etPwd = view.findViewById(R.id.edt_inputpswone);
        EditText etCode = view.findViewById(R.id.edt_inputcode);
        EditText etGoogleCode = view.findViewById(R.id.edt_inputgooglecode);
        RelativeLayout rly_googlecode_body = view.findViewById(R.id.rly_googlecode_body);
        TextView tv_mail = view.findViewById(R.id.tv_mail);
        Countdownbutton countdownbutton = view.findViewById(R.id.tv_getcode);

        if (MyApp.getUserData() != null && MyApp.getUserData().getData() != null && MyApp.getUserData().getData().isBindGoogleCode()) {
            rly_googlecode_body.setVisibility(View.VISIBLE);
        } else {
            rly_googlecode_body.setVisibility(View.GONE);
        }

        edtInputphone = view.findViewById(R.id.edt_inputphone);
        tvSetphonecode = view.findViewById(R.id.tv_setphonecode);
        tvClickphonecountry = view.findViewById(R.id.tv_clickphonecountry);

//        if (MyApp.getUserData() != null && MyApp.getUserData().getData() != null && MyApp.getUserData().getData().getUser() != null) {
//            String strPhone = MyApp.getUserData().getData().getUser().getPhone();
//            edtInputphone.setText(strPhone.length() > 6 ? strPhone.substring(0, 3) + "****" + strPhone.substring(strPhone.length() - 4, strPhone.length()) : strPhone);
//        }

        if (MyApp.getMail() != null) {
            String[] split = MyApp.getMail().split("@");
            tv_mail.setText(split[0].length() > 4 ? split[0].substring(0, 2) + "****" + split[0].substring(split[0].length() - 2, split[0].length()) + "@" + split[1] : MyApp.getMail());
        }

        tvClickphonecountry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                successListener2.oninToFundArea(true);
//                showDownPop(tvSetphonecode);
            }
        });


        view.findViewById(R.id.tv_getcode).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (successListener1 != null) {
                    countdownbutton.start();
                    successListener1.onSendSms(Integer.parseInt(tvSetphonecode.getText().toString()) + "");
                }
            }
        });

        view.findViewById(R.id.tv_tursubmit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(etPwd.getText().toString())) {

                    Toast.makeText(activity, activity.getString(R.string.wallet_hint_pleaseinputpsw), Toast.LENGTH_SHORT).show();
                    return;
                }
                if (TextUtils.isEmpty(etCode.getText().toString())) {

                    Toast.makeText(activity, activity.getString(R.string.profile_hint_warn11), Toast.LENGTH_SHORT).show();
                    return;
                }
                if (rly_googlecode_body.isShown() && TextUtils.isEmpty(etGoogleCode.getText().toString())) {

                    Toast.makeText(activity, activity.getString(R.string.google_hint_iputgooglecode), Toast.LENGTH_SHORT).show();
                    return;
                }
                if (successListener != null) {
                    successListener.onSuccess(etPwd.getText().toString(), etCode.getText().toString(), etGoogleCode.getText().toString());
                }
            }
        });

        alert.setCanceledOnTouchOutside(true);
        alert.show();

        return alert;
    }


    public static AlertDialog showVerify(Activity activity, String submitBtnStr, IEnterPwdListener2 successListener, IEnterPwdListener3 successListener1, IEnterPwdListener4 successListener2) {
        for (int i = 0; i < countys.length; i++) {
            countys[i] = activity.getResources().getString(county[i]);
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_verify, null, false);
        AlertDialog alert = builder.setView(view)
                .create();

        EditText etPwd = view.findViewById(R.id.edt_inputpswone);
        EditText etCode = view.findViewById(R.id.edt_inputcode);
        Countdownbutton countdownbutton = view.findViewById(R.id.tv_getcode);
        TextView tvSubmit = view.findViewById(R.id.tv_tursubmit);
        tvSubmit.setText(submitBtnStr);
        edtInputphone = view.findViewById(R.id.edt_inputphone);
        tvSetphonecode = view.findViewById(R.id.tv_setphonecode);
        tvClickphonecountry = view.findViewById(R.id.tv_clickphonecountry);

//        if (MyApp.getUserData() != null && MyApp.getUserData().getData() != null && MyApp.getUserData().getData().getUser() != null) {
//            String strPhone = MyApp.getUserData().getData().getUser().getPhone();
//            edtInputphone.setText(strPhone.length() > 6 ? strPhone.substring(0, 3) + "****" + strPhone.substring(strPhone.length() - 4, strPhone.length()) : strPhone);
//        }


        tvClickphonecountry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                successListener2.oninToFundArea(true);
//                showDownPop(tvSetphonecode);
            }
        });


        view.findViewById(R.id.tv_getcode).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (successListener1 != null) {
                    countdownbutton.start();
                    successListener1.onSendSms(Integer.parseInt(tvSetphonecode.getText().toString()) + "");
                }
            }
        });

        view.findViewById(R.id.tv_tursubmit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(etPwd.getText().toString())) {

                    Toast.makeText(activity, activity.getString(R.string.wallet_hint_pleaseinputpsw), Toast.LENGTH_SHORT).show();
                    return;
                }
                if (TextUtils.isEmpty(etCode.getText().toString())) {

                    Toast.makeText(activity, activity.getString(R.string.profile_hint_warn11), Toast.LENGTH_SHORT).show();
                    return;
                }
                if (successListener != null) {
                    successListener.onSuccess(etPwd.getText().toString(), etCode.getText().toString(), "");
                }
            }
        });

        alert.setCanceledOnTouchOutside(true);
        alert.show();

        return alert;
    }

    private static CommonPopupWindow popupWindow;
    public static List<String> countrys = new ArrayList<>();
    public static Map<String, String> countryMap = new HashMap<>();

    //向下弹出
    public static void showDownPop(View view) {
        Context context = view.getContext();
        if (countrys.size() == 0) {
            for (int i = 0; i < countys.length; i++) {
                countrys.add(countys[i]);
                countryMap.put(countys[i], countyID[i]);
            }
        }
        if (popupWindow != null && popupWindow.isShowing()) return;
        popupWindow = new CommonPopupWindow.Builder(context)
                .setView(R.layout.popup_down)
                .setWidthAndHeight(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                .setAnimationStyle(R.style.AnimDown)
                .setViewOnclickListener(new CommonPopupWindow.ViewInterface() {
                    @Override
                    public void getChildView(View view, int layoutResId) {
                        //获得PopupWindow布局里的View
                        switch (layoutResId) {
                            case R.layout.popup_down:
                                RecyclerView recycle_view = (RecyclerView) view.findViewById(R.id.recycle_view);
                                recycle_view.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
//                recycle_view.setLayoutManager(new GridLayoutManager(this, 3));
                                PopupAdapter mAdapter = new PopupAdapter(context, countrys);
                                recycle_view.setAdapter(mAdapter);
                                mAdapter.setOnItemClickListener(new MyOnclickListener() {
                                    @Override
                                    public void onItemClick(View view, int position) {

                                        tvSetphonecode.setText(countryMap.get(countrys.get(position)));
                                        tvClickphonecountry.setText(countrys.get(position));

                                        if (popupWindow != null) {
                                            popupWindow.dismiss();
                                        }
                                    }
                                });
                                break;
                        }
                    }
                })
                .setOutsideTouchable(true)
                .create();
        popupWindow.showAsDropDown(view);
        //得到button的左上角坐标
//        int[] positions = new int[2];
//        view.getLocationOnScreen(positions);
//        popupWindow.showAtLocation(findViewById(android.R.id.content), Gravity.NO_GRAVITY, 0, positions[1] + view.getHeight());
    }


    public static void enterPayPsw(Activity activity, IEnterPwdListener successListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
//        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_pwd3, null, false);

        PayPasswordView payPasswordView = new PayPasswordView(activity);
        AlertDialog alert = builder.setView(payPasswordView)
                .create();
        payPasswordView.setFullClickListener(new PayPasswordView.FullClickListener() {
            @Override
            public void FullListener(String paypsw) {
                if (successListener != null) {
                    successListener.onSuccess(paypsw);
                    alert.dismiss();
                }
            }
        });

//        TextView tvTitle = view.findViewById(R.id.tv_title);
//        tvTitle.setText(title_hint);
//        EditText etPwd = view.findViewById(R.id.et_pwd);
//        etPwd.setInputType(inputType);//InputType.TYPE_CLASS_TEXT
//        etPwd.setHint(title_hint);
//        etPwd.setHintTextColor(activity.getResources().getColor(R.color.colorPrimary666666));
//        etPwd.setTextColor(activity.getResources().getColor(R.color.colorPrimary444444));
//        etPwd.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.shape_white));
//        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
////                Toast.makeText(activity, "取消输入", Toast.LENGTH_SHORT).show();
//                hide(activity, etPwd);
//                alert.dismiss();
//
//            }
//        });
//        view.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (successListener != null) {
//                    successListener.onSuccess(etPwd.getText().toString());
//                }
//                hide(activity, etPwd);
////                Toast.makeText(activity, "密码是 " + etPwd.getText().toString(), Toast.LENGTH_SHORT).show();
//                alert.dismiss();
//            }
//        });
        alert.show();
    }


    public static void enterGoogleCode(Activity activity, IEnterPwdListener successListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
//        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_pwd3, null, false);

        GoogleCodewordView googleCodewordView = new GoogleCodewordView(activity);
        AlertDialog alert = builder.setView(googleCodewordView)
                .create();
        googleCodewordView.setFullClickListener(new GoogleCodewordView.FullClickListener() {
            @Override
            public void FullListener(String paypsw) {
                if (successListener != null) {
                    successListener.onSuccess(paypsw);
                    alert.dismiss();
                }
            }
        });

//        TextView tvTitle = view.findViewById(R.id.tv_title);
//        tvTitle.setText(title_hint);
//        EditText etPwd = view.findViewById(R.id.et_pwd);
//        etPwd.setInputType(inputType);//InputType.TYPE_CLASS_TEXT
//        etPwd.setHint(title_hint);
//        etPwd.setHintTextColor(activity.getResources().getColor(R.color.colorPrimary666666));
//        etPwd.setTextColor(activity.getResources().getColor(R.color.colorPrimary444444));
//        etPwd.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.shape_white));
//        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
////                Toast.makeText(activity, "取消输入", Toast.LENGTH_SHORT).show();
//                hide(activity, etPwd);
//                alert.dismiss();
//
//            }
//        });
//        view.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (successListener != null) {
//                    successListener.onSuccess(etPwd.getText().toString());
//                }
//                hide(activity, etPwd);
////                Toast.makeText(activity, "密码是 " + etPwd.getText().toString(), Toast.LENGTH_SHORT).show();
//                alert.dismiss();
//            }
//        });
        alert.show();
    }


    public static void enterHost(Activity activity, CharSequence title_hint,CharSequence content_hint, int inputType, IEnterPwdListener successListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_host3, null, false);
        AlertDialog alert = builder.setView(view)
                .create();
        TextView tvTitle = view.findViewById(R.id.tv_title);
        tvTitle.setText(title_hint);
        EditText etPwd = view.findViewById(R.id.et_pwd);
        etPwd.setInputType(inputType);//InputType.TYPE_CLASS_TEXT
        etPwd.setHint(title_hint);
        etPwd.setHintTextColor(activity.getResources().getColor(R.color.colorPrimary666666));
        etPwd.setTextColor(activity.getResources().getColor(R.color.colorPrimary444444));
        etPwd.setText(content_hint);
//        etPwd.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.shape_white));
        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(activity, "取消输入", Toast.LENGTH_SHORT).show();
                hide(activity, etPwd);
                alert.dismiss();

            }
        });
        view.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (successListener != null) {
                    successListener.onSuccess(etPwd.getText().toString());
                }
                hide(activity, etPwd);
//                Toast.makeText(activity, "密码是 " + etPwd.getText().toString(), Toast.LENGTH_SHORT).show();
                alert.dismiss();
            }
        });
        alert.show();
    }

}
